﻿using System.Collections.Generic;
using System.Text;
using Habanero.Base;

namespace FireStarter.Base.BusinessObjectMerger
{
    public class CompareResult
    {
        public CompareResult(IList<IBOError> compareFailureList)
        {
            CompareFailureList = compareFailureList;
        }


        public CompareResult(CompareFailureMessage error)
        {
            CompareFailureList = new List<IBOError> {error};
        }

        public CompareResult(string errMessage)
            : this(new CompareFailureMessage(errMessage))
        {

        }

        /// <summary>
        /// Are the two Mergeable Business Objects Equal
        /// </summary>
        public bool AreEqual { get {return CompareFailureList.Count == 0; } }
        /// <summary>
        /// If the Mergeable Business Objects are compared then this will return
        /// a list of Compare Failures if Any
        /// </summary>
        public IList<IBOError> CompareFailureList { get; private set; }

        public void AddResult(CompareResult compareResult)
        {
            foreach (var boError in compareResult.CompareFailureList)
            {
                this.CompareFailureList.Add(boError);
            }
        }

        public void AddFailure(string errorMessage)
        {
            AddFailure(new CompareFailureMessage(errorMessage));
        }

        public void AddFailure(CompareFailureMessage compareResult)
        {
            CompareFailureList.Add(compareResult);
        }

        public string CompareFailures()
        {
            StringBuilder sb = new StringBuilder("");
            foreach (var boError in CompareFailureList)
            {
                sb.Append(boError.Message + "\n ");
            }

            return sb.ToString();
        }

    }
}